<?php

/**
 * Description of BaseAction
 *
 * @author chacha
 * @date 2015-12-21
 */
class BaseAction extends Action{
    var $uid;
    var $role;
    var $userinfo;
    var $account;
    var $webtitle;
    var $priArr;//隐私控制标志数组

    public function __construct() {
        parent::__construct();
        
        $this->uid = sVerify();
        
        if ($this->uid>0) {
            //是否有新短信
            $this->assign('msgCount', 0);
            $sql = "SELECT * FROM xia_office_log WHERE uid=".$this->uid." and id NOT IN (select logid from xia_log_view where uid=".$this->uid.")";
            $resMessage = M('office_log')->query($sql);
            if ($resMessage) {
                $this->assign('msgCount', count($resMessage));
            }

            $resAccount = M('account')->where('uid='.$this->uid)->find();//为了保证用户能及时获取状态，每次请求都查表
            $this->account = $resAccount;

            

            $this->userinfo = M('user_info')->where('uid='.$this->uid)->find();
            $this->assign("uid", $this->uid);
            $this->assign("userinfo", $this->userinfo);
            $this->assign('account', $this->account);
        }
        
        //友情链接
        $resLink = M('friendlink')->where('status<>0')->select();
        if ($resLink) {
            $this->assign('links', $resLink);
        }
        Log::write("[BaseAction::__construct]uid:".$this->uid, Log::INFO);
        $this->assign('on', 0);
    }
    
    public function jsonpf($msg='') {
        $callback = I('callback', 'callback');
        echo $callback."(".json_encode(array('success'=>0,'msg'=>$msg)).")";
        exit;
    }
    
    public function jsonps($c=1, $msg='') {
        $callback = I('callback', 'callback');
        echo $callback."(".json_encode(array('success'=>$c,'msg'=>$msg)).")";
        exit;
    }
    
    public function Page404() {
        $this->display(App\Common\Constvars::TPL_404);
    }
}
